/*  
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package operacionesDB;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author David
 */
public class ConnectionDB {

    public String DB = "pretamolibro";
    public String login = "root";
    public String pass = "";
    public String url = "jdbc:mysql://localhost/" + DB;

    public ConnectionDB() {
    }

    public Connection getConectar() {
        Connection con = null;
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
            con = DriverManager.getConnection(url, login, pass);
            if (con != null) {
                //System.out.println("Conexión a base de datos " + url + " ... Ok");
            }
        } catch (SQLException ex) {
            System.out.println("Hubo un problema al intentar conectarse con la base de datos " + url);
        } catch (ClassNotFoundException ex) {
            System.out.println(ex);
        }
        return con;
    }

    public void cerrar(Connection conn) {
        try {
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(ConnectionDB.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
